<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>新增商户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../js/layui/css/layui.css" media="all">
</head>
<body style="height: 700px;">
<div style="height: 100%;width:80%;margin:15px auto;overflow:auto;" id="aaa">
    <form class="layui-form" action="">
        <div class="layui-form-item">
            <label class="layui-form-label">商户名称<span style="color:red">*</span></label>
            <div class="layui-input-block">
                <input type="text" name="name" required  lay-verify="required" placeholder="请输入商户名称" autocomplete="off" class="layui-input">
            </div>
        </div>
       <!-- <div class="layui-form-item">
            <label class="layui-form-label">商户编号</label>
            <div class="layui-input-block">
                <input type="text" name="bh" required  lay-verify="required" placeholder="请输入商户编号" autocomplete="off" class="layui-input">
            </div>
        </div>-->
        <div class="layui-form-item">
            <label class="layui-form-label">所属物业<span style="color:red">*</span></label>
            <div class="layui-input-block">
                <select lay-search id="cla" required  lay-verify="required">
                    <option id="eee" disabled selected></option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">负责人</label>
            <div class="layui-input-block">
                <input type="text" name="fzr"  placeholder="请输入负责人姓名" autocomplete="off" class="layui-input">
            </div>
        </div>

        <!--<div class="layui-form-item">
            <label class="layui-form-label">登录密码</label>
            <div class="layui-input-block">
                <input type="text" name="password" required  lay-verify="required" placeholder="请输入商户登录密码" autocomplete="off" class="layui-input">
            </div>
            &lt;!&ndash;<div class="layui-form-mid layui-word-aux">辅助文字</div>&ndash;&gt;
        </div>-->
        <div class="layui-form-item">
            <label class="layui-form-label">商户地址</label>
            <div class="layui-input-block">
                <input type="text" name="address"  placeholder="请输入商户的地址" autocomplete="off" class="layui-input">
            </div>
            <!--<div class="layui-form-mid layui-word-aux">辅助文字</div>-->
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <textarea class="layui-textarea" type="text" name="message" placeholder="请输入备注" autocomplete="off" class="layui-input"></textarea>
            </div>
        </div>

        <div class="layui-form-item" style="margin-top: 20px">
            <div class="layui-input-block">
                <button class="layui-btn" id="addBusiness" lay-submit lay-filter="addBusiness">立即添加</button>
                <button type="reset" id="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>
    </form>
</div>
<script src="../../js/layui/layui.js"></script>
<script src="../../js/layui/layui.all.js"></script>
<script src="../../js/token.js"></script>
<script src="../../js/config.js"></script>

<script>
    layui.use(['form' , 'jquery' , 'upload'], function(){
        var form = layui.form;
        var $ = layui.jquery;

        //添加操作
        form.on('submit(addBusiness)',function(data){
            var wuye = $("#cla").find("option:selected").val();
            data.field.wyid=wuye;
            if(wuye==null || wuye==""){
                layer.msg('请选择所属物业');
                return false;
            }
            $.ajax({
                url: HOST+"business/addBusiness"
                , type: "POST"
                , contentType: 'application/json'
                , data: JSON.stringify(data.field)
                , success: function (data) {
                    if (data.code == 500) {
                        layer.msg(data.data)
                    }else if(data.code==200) {
                        layer.close(layer.index);
                        layer.msg('添加成功');
                        setTimeout(function () {
                            window.location.reload();
                        }, 3000);
                    }else{
                        layer.msg('拒绝访问');
                    }
                }
                ,error:function () {
                    console.log("ajax error");
                }
            })
            return false;
        });

        //遍历物业下选框
        $.ajax({
            url: HOST+"wuye/selectwuyestatus"
            , type: "POST"
            , contentType: 'application/json'
            , data: {'status': 1}
            , success: function (data) {
                $.each(data.data, function (index, item) {
                    $('#cla').append(new Option(item.wyname, item.id));// 下拉菜单里添加元素
                });
                layui.form.render("select");
            }
        });
    });
</script>
</body>
</html>